import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/education/train_program/offline_training/workers_train_achievement/workers_train_achievement_controller.dart';

///职工培训成绩
class WorkersTrainAchievementPage extends StatelessWidget {
  WorkersTrainAchievementPage({super.key});

  final controller = Get.put(WorkersTrainAchievementController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
            margin: EdgeInsets.only(left: 16.w, top: 14.w, right: 16.w, bottom: 14.w),
            decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(10)),
            ),
            child: _geBottomView(),
          );
        });
  }

  Widget _geBottomView() {
    return Container(
      padding: EdgeInsets.only(left: 16.w, top: 14.w, right: 16.w, bottom: 14.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(
          Radius.circular(6.w),
        ),
      ),
      child: Column(
        children: [
          Container(
            alignment: Alignment.center,
            padding: EdgeInsets.symmetric(vertical: 10.w),
            decoration: BoxDecoration(
              color: const Color(0xFFF1F2F7),
              borderRadius: BorderRadius.all(
                Radius.circular(6.w),
              ),
            ),
            child: Row(
              children: [
                Expanded(
                    flex: 1, child: Center(child: Text('姓名', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 12.sp, color: const Color(0xFF495061))))),
                Expanded(
                    flex: 1, child: Center(child: Text('讲师', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 12.sp, color: const Color(0xFF495061))))),
                Expanded(
                    flex: 1, child: Center(child: Text('分数', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 12.sp, color: const Color(0xFF495061))))),
                Expanded(
                    flex: 1, child: Center(child: Text('课时', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 12.sp, color: const Color(0xFF495061))))),
                Expanded(
                    flex: 1,
                    child: Center(child: Text('考核结果', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 12.sp, color: const Color(0xFF495061))))),
              ],
            ),
          ),
          Expanded(
              child: ListView.separated(
                  itemBuilder: (context, index) {
                    return Container(
                      alignment: Alignment.center,
                      padding: EdgeInsets.symmetric(vertical: 10.w),
                      decoration: BoxDecoration(
                        color: index % 2 != 0 ? const Color(0xFFF1F2F7) : Colors.white,
                        borderRadius: BorderRadius.all(
                          Radius.circular(6.w),
                        ),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          _rowFirst('${controller.data?[index].userName}'),
                          _rowFirst('${controller.data?[index].lecturerName}'),
                          _rowFirst('${controller.data?[index].fraction}'),
                          _rowFirst('${controller.data?[index].classHour}'),
                          //考核结果 0:优秀1:良好2:合格3:不合格
                          _rowFirst(_assessmentResults(controller.data?[index].assessmentResults)),
                        ],
                      ),
                    );
                  },
                  separatorBuilder: (context, index) => const SizedBox(width: 0, height: 0),
                  itemCount: controller.data!.length)),
        ],
      ),
    );
  }

  Widget _rowFirst(String name) {
    return Expanded(
      flex: 1,
      child: Center(
        child: Text(
          name,
          style: TextStyle(
            fontWeight: FontWeight.w400,
            fontSize: 12.sp,
            color: const Color(0xFF818499),
          ),
        ),
      ),
    );
  }

  ///考核结果 0:优秀1:良好2:合格3:不合格
  String _assessmentResults(int? s) {
    switch (s) {
      case 0:
        return '优秀';
      case 1:
        return '良好';
      case 2:
        return '合格';
      case 3:
        return '不合格';
      default:
        return '';
    }
  }
}
